import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_date_type.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/app/data/entities/home/warning/alarm_resp_entity.dart';
import 'package:safetymonitor/generated/assets.dart';
import 'controller.dart';

///预警报警待完成
class AlarmNoCompletedPage extends StatelessWidget {
  AlarmNoCompletedPage({super.key});

  final controller = Get.put(NoCompletedController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return CustomEasyRefreshList<AlarmRespEntity>(
            dataLoad: controller.getData,
            key: controller.globalKey,
            itemBuilder: (AlarmRespEntity item, int index) {
              return CustomTitleChartPage(
                contentPadding:
                    EdgeInsets.only(right: 16.w, left: 16.w, top: 16.w),
                title: item.companyName,
                titleRightWidget: controller.getStatueView(item.disposalStatus),
                child: Stack(
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Expanded(
                              child: _getTextView(
                                title:
                                    '${CustomDateType.getDataType(item.dataType)}级别:',
                                value: CustomDateType.getAlarmType(item.alarmLevel, item.dataType, isShow: true),
                              ),
                            ),
                            Expanded(
                                child: _getTextView(
                                    title:
                                        '${CustomDateType.getDataType(item.dataType)}值:',
                                    value: '${item.val==0?'': item.val}')),
                          ],
                        ),
                        _getTextView(
                          title: '系统-类别:',
                          value: item.categoryZh,
                        ),
                        _getTextView(
                            title: '报警时长:',
                            value: '${item.alarmTimeMin}分钟'),
                        _getTextView(
                            title: '报警时间:',
                            value: '${item.alarmStartTime}'.millTS2Str()),
                      ],
                    ),
                    Positioned(
                      right: 0,
                      bottom: 0,
                      child: Stack(
                        alignment: Alignment.center,
                        children: [
                          SvgPicture.asset(
                            Assets.svgIconEnter,
                            fit: BoxFit.cover,
                          ),
                          Icon(
                            Icons.arrow_forward,
                            size: 20.w,
                            color: Colors.white,
                          ).marginOnly(left: 7.w, top: 6.w),
                        ],
                      ),
                    ),
                    Positioned(
                      right: 44,
                      bottom: 0,
                      child: Visibility(
                        visible: item.supervisionStatusStr != '0', //0、无操作按钮权限
                        child: Stack(
                          alignment: Alignment.center,
                          children: [
                            SvgPicture.asset(
                              'assets/svg/icon_enter_green.svg',
                              fit: BoxFit.cover,
                            ),
                            Text(
                              item.supervisionStatusStr == '1'||item.supervisionStatusStr == '2'? '督办' :  item.supervisionStatusStr == '3'?'派发':'处置',
                              style: TextStyle(
                                fontSize: 14.sp,
                                height: 1.2,
                                fontWeight: FontWeight.w400,
                                color: Colors.white,
                              ),
                            )
                          ],
                        ).clickOnce(() {
                           controller.onClickOperateDialog(item);
                        }),
                      ),
                    ),
                  ],
                ),
              ).clickOnce(() {
                controller.goDetails(item);
              });
            },
          );
        });
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 14.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xffC7CEE5),
              ),
            ),
            AppGaps.hGap6,
            Expanded(
                child: Text(
              value,
              style: TextStyle(
                fontSize: 14.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xff1D3452),
              ),
            ))
          ],
        ),
        AppGaps.vGap10,
      ],
    );
  }

}
